package com.iterator.controller.web.promotionController;

import com.iterator.bean.web.pojo.BaseRespVo;
import com.iterator.bean.web.pojo.zql.InfoData;
import com.iterator.bean.web.pojo.zql.Topic;
import com.iterator.bean.web.zql.bo.TopicBO;
import com.iterator.service.web.promotionService.TopicService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author : L
 * @ProjectName : project-2
 * @Date : 1/10/2021
 * @Description :
 */
@RestController
@RequestMapping("admin/topic")
public class TopicController {
    @Autowired
    TopicService topicService;

    @RequestMapping("list")
    @RequiresPermissions("admin:topic:list")
    public BaseRespVo list(TopicBO topicBO) {
        InfoData<Topic> topicInfoData = topicService.queryTopicList(topicBO);
        return BaseRespVo.ok(topicInfoData);
    }

    @RequestMapping("create")
    @RequiresPermissions("admin:topic:create")
    public BaseRespVo create(@RequestBody Topic topic) {
        Date addTime = new Date();
        topic.setAddTime(addTime);
        Topic topic1 = topicService.insertTopic(topic);
        return BaseRespVo.ok(topic1);
    }


    @RequestMapping("update")
    @RequiresPermissions("admin:topic:update")
    public BaseRespVo update(@RequestBody Topic topic) {
        Date updateTime = new Date();
        topic.setUpdateTime(updateTime);
        Topic topic1 = topicService.updateTopic(topic);
        return BaseRespVo.ok(topic1);
    }


    @RequestMapping("delete")
    @RequiresPermissions("admin:topic:delete")
    public BaseRespVo delete(@RequestBody Topic topic) {
        topicService.deleteTopic(topic);
        return BaseRespVo.ok();
    }
}
